import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-03-26
 * Time:11:23
 */
public class Demo1 {                                                   
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("0000");

        Connection connection = dataSource.getConnection();

//        String s1 = new String("insert into borrow_info values (19, 10, 3, '2019-9-25 17:50:00' , '2019-10-25 17:50:00')");
//        String s2 = new String("select * from book where category_id = 3");
//        PreparedStatement statement = connection.prepareStatement(s2);
//        ResultSet resultSet = statement.executeQuery();
//        while (resultSet.next()){
//            int id = resultSet.getInt("id");
//            String name = resultSet.getString("name");
//            String author = resultSet.getString("author");
//            String price = resultSet.getString("price");
//            int category_id = resultSet.getInt("category_id");
//            System.out.println("{id="+id+" name="+name+" author="+author+" price="+price+"category_id="+category_id+"}");
//        }

//        String s3 = new String("update book set price = 61.20 where name = '深入理解Java虚拟机'");
//        PreparedStatement statement = connection.prepareStatement(s3);
//        int ret = statement.executeUpdate();
//        System.out.println(ret);

        String s4 = new String(" select * from borrow_info order by id desc limit 1;");
        PreparedStatement statement = connection.prepareStatement(s4);
        int ret = statement.executeUpdate();
        System.out.println(ret);

        statement.close();
        connection.close();
    }
}
